package com.youzan.cloud.component.biz.member.service.impl;
import com.youzan.cloud.component.biz.member.common.util.OutResultUtil;
import com.youzan.cloud.component.biz.member.dto.BaseResult;
import com.youzan.cloud.component.biz.member.dto.LogDTO;
import com.youzan.cloud.component.biz.member.dto.MemberBaseDto;
import com.youzan.cloud.component.biz.member.service.IBaseService;
import com.youzan.cloud.component.biz.member.service.ILogService;
import com.youzan.cloud.connect.service.sdk.ConnectServiceCaller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

@Service
public abstract class AbstractService implements IBaseService {

    @Autowired
    private ILogService logService;

    @Autowired
    ConnectServiceCaller connectServiceCaller;

    @Transactional
    public BaseResult execute(MemberBaseDto memberBaseDto){
        logService.addLog(buildLog(memberBaseDto));
        try{
            return  doBiz(memberBaseDto);
        } catch (Exception e){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
           return handleException(e);
        }
    }

    public abstract LogDTO buildLog(Object inputParam);

    public abstract BaseResult handleException(Exception e);


    @Override
    public abstract BaseResult doBiz(MemberBaseDto memberBaseDto);
}
